//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using OpenLS.Core.Serialization;
using OpenLS.Spreadsheet.Data;

namespace OpenLS.Spreadsheet.Pivot
{
    internal class PivotTableBoolean : PivotTableValue
    {
        private readonly List<Index> _x = new List<Index>();
        private string _c;
        private UInt32? _cp;
        private Boolean? _f;
        private Boolean? _u;
        private Boolean _v;
        internal const string xmlName = "b";

        #region IOfficeXmlSerializable Members

        public override void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                _v = c.GetBoolean("v");
                _u = c.GetOptionalBoolean("u");
                _f = c.GetOptionalBoolean("f");
                _c = c.GetOptionalString("c");
                _cp = c.GetOptionalUInteger("cp");
                _x.Clear();
                _x.AddRange(c.ReadOptionalWhile<Index>("x"));
            }
        }

        public override void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.SetBoolean("v", _v);
                c.SetOptionalBoolean("u", _u);
                c.SetOptionalBoolean("f", _f);
                c.SetOptionalString("c", _c);
                c.SetOptionalUInteger("cp", _cp);
                c.WriteElements(_x);
            }
        }

        public override object Value
        {
            get { return _v; }
        }

        #endregion
    }
}